package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserWithdrawLog;
import com.ruoyi.system.service.IUserWithdrawLogService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.common.domain.ZhDeptInfo;

/**
 * 用户提现记录 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-06-21
 */
@Controller
@RequestMapping("/system/userWithdrawLog")
public class UserWithdrawLogController extends BaseController
{
    private String prefix = "system/userWithdrawLog";

	@Autowired
	private IUserWithdrawLogService userWithdrawLogService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userWithdrawLog:view")
	@GetMapping()
	public String userWithdrawLog(UserWithdrawLog userWithdrawLog,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,userWithdrawLog.getParams())));
		return prefix + "/userWithdrawLog";
	}
	
	/**
	 * 查询用户提现记录列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userWithdrawLog:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserWithdrawLog userWithdrawLog)
	{
		startPage();
        List<UserWithdrawLog> list = userWithdrawLogService.selectUserWithdrawLogList(userWithdrawLog);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出用户提现记录列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userWithdrawLog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserWithdrawLog userWithdrawLog)
    {
    	List<UserWithdrawLog> list = userWithdrawLogService.selectUserWithdrawLogList(userWithdrawLog);
        ExcelUtil<UserWithdrawLog> util = new ExcelUtil<UserWithdrawLog>(UserWithdrawLog.class);
        return util.exportExcel(list, "userWithdrawLog");
    }
	
	/**
	 * 新增用户提现记录
	 */
	@RequiresPermissions("system:userWithdrawLog:add")
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	public String add(UserWithdrawLog userWithdrawLog,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,userWithdrawLog.getParams())));
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存用户提现记录
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userWithdrawLog:add")
	@Log(title = "用户提现记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserWithdrawLog userWithdrawLog)
	{		
		return toAjax(userWithdrawLogService.insertUserWithdrawLog(userWithdrawLog));
	}

	/**
	 * 修改用户提现记录
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userWithdrawLog:edit")
	@GetMapping("/edit/{id}")
	public String edit(UserWithdrawLog userWithdrawLog,@PathVariable("id") Integer id, ModelMap mmap)
	{
		UserWithdrawLog result = userWithdrawLogService.selectUserWithdrawLogById(id);
		mmap.put("userWithdrawLog", result);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,userWithdrawLog.getParams())));
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存用户提现记录
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userWithdrawLog:edit")
	@Log(title = "用户提现记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserWithdrawLog userWithdrawLog)
	{		
		return toAjax(userWithdrawLogService.updateUserWithdrawLog(userWithdrawLog));
	}
	
	/**
	 * 删除用户提现记录
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userWithdrawLog:remove")
	@Log(title = "用户提现记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(UserWithdrawLog userWithdrawLog,String ids)
	{		
		return toAjax(userWithdrawLogService.deleteUserWithdrawLogByIds(ids));
	}

	/**
	 * 设置已转账
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:userWithdrawLog:edit")
	@Log(title = "设置已转账",businessType = BusinessType.UPDATE)
	@PutMapping( "/transfer/{id}")
	@ResponseBody
	public AjaxResult setTransfered(@PathVariable("id") String id)
	{
		return toAjax(userWithdrawLogService.updateTransferedById(Integer.valueOf(id)));
	}

}
